#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
验证work_comments表是否成功创建
"""

import os
import sys
from sqlalchemy import text

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from database.connection import engine

def verify_table():
    """
    验证work_comments表是否存在
    """
    try:
        with engine.connect() as conn:
            # 检查表是否存在
            result = conn.execute(text("SHOW TABLES LIKE 'work_comments'"))
            table_exists = result.fetchone() is not None
            
            if table_exists:
                print("✅ work_comments表已成功创建")
                
                # 获取表结构
                result = conn.execute(text("DESCRIBE work_comments"))
                print("\n📋 表结构详情:")
                print("-" * 80)
                print(f"{'字段名':<15} {'类型':<20} {'允许NULL':<10} {'键':<10} {'默认值':<15} {'备注'}")
                print("-" * 80)
                
                for row in result:
                    field, type_, null, key, default, extra = row
                    print(f"{field:<15} {type_:<20} {null:<10} {key:<10} {str(default or ''):<15} {extra}")
                
                # 检查记录数
                result = conn.execute(text("SELECT COUNT(*) FROM work_comments"))
                count = result.fetchone()[0]
                print(f"\n📊 当前记录数: {count}")
                
                return True
            else:
                print("❌ work_comments表不存在")
                return False
                
    except Exception as e:
        print(f"❌ 验证失败: {str(e)}")
        return False

if __name__ == "__main__":
    verify_table()